package com.ciaojian.worker.strategy.workerstatus;

import com.ciaojian.core.constant.RedisConstant;
import com.ciaojian.core.enums.business.WorkerWorkerStatusEnum;
import com.ciaojian.core.model.Worker;
import com.ciaojian.core.util.DateUtil;
import com.ciaojian.core.util.RedisUtil;
import com.ciaojian.worker.factory.StatusModifierFactory;
import org.springframework.stereotype.Component;

/**
 * 外出修改器
 *
 * @author oxiny
 */
@Component
public class OutsideModifier implements StatusModifier {

    @Override
    public void handle(Worker worker) {
        // 发型师外出十分钟后把状态改回来
        worker.setWorkerStatus(WorkerWorkerStatusEnum.OUTSIDE);
        worker.updateById();
        // kafka队列
        // 先用Redis顶一下
        RedisUtil.zSet(RedisConstant.WORKER_OUTSIDE, worker.getId(), DateUtil.current() + 10 * 60 * 1000);
    }

    @Override
    public WorkerWorkerStatusEnum getStatus() {
        return WorkerWorkerStatusEnum.OUTSIDE;
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        StatusModifierFactory.register(this);
    }
}
